package com.wxzz.elearing.evaluation.api.admin;


import com.wxzz.elearing.evaluation.dto.InTopicDto;
import com.wxzz.elearing.evaluation.dto.TopicDto;
import com.wxzz.elearing.evaluation.dto.UpdateSuggestDto;
import com.wxzz.elearing.evaluation.entity.*;
import com.wxzz.elearing.evaluation.service.ITopicService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 测评题库 前端控制器
 * </p>
 *
 * @author
 * @since 2021-04-10
 */
@RestController
@RequestMapping("/topic")
@Api(tags = "测评题库接口(总后台)")
public class TopicController {

    @Autowired
    private ITopicService topicService;

    @ApiOperation(value = " 添加或修改题目分类(总后台)", notes = "添加或修改题目分类(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "saveTopicCategory", method = RequestMethod.POST)
    public ReturnVO saveTopicCategory(@RequestBody TopicCategory topicCategory) {
        return topicService.saveTopicCategory(topicCategory);
    }

    @ApiOperation(value = " 删除题目分类(总后台)", notes = " 删除题目分类(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "deleteTopicCategory/{topicCategoryId}", method = RequestMethod.POST)
    public ReturnVO deleteTopicCategory(@PathVariable Long topicCategoryId) {
        return topicService.deleteTopicCategory(topicCategoryId);
    }

    @ApiOperation(value = " 题目分类层级展示(总后台)", notes = " 题目分类层级展示(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "listTopicCategoryByPid", method = RequestMethod.POST)
    public ReturnVO<List<TopicCategory>> listTopicCategoryByPid() {
        return topicService.listTopicCategoryByPid();
    }

    @ApiOperation(value = " 根据当前id查询(总后台)", notes = " 根据当前id查询(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "selectPid/{id}", method = RequestMethod.POST)
    public ReturnVO<Long> selectPid(@PathVariable Long id) {
        return topicService.selectPid(id);
    }

    @ApiOperation(value = " 添加题目(总后台)", notes = " 添加题目(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "saveTopic", method = RequestMethod.POST)
    public ReturnVO saveTopic(@RequestBody Topic topic) {
        return topicService.saveTopic(topic);
    }

    @ApiOperation(value = " 根据id删除题目(总后台)", notes = " 根据id删除题目(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "deleteTopicById/{id}", method = RequestMethod.POST)
    public ReturnVO deleteTopicById(@PathVariable Long id) {
        return topicService.deleteTopicById(id);
    }

    @ApiOperation(value = " 删除工厂体检/星级认证/能力测评关联题目(总后台)", notes = " 删除工厂体检/星级认证/能力测评关联题目(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "deleteBusinessCategoryTopic/{businessCategoryTopicId}", method = RequestMethod.POST)
    public ReturnVO deleteBusinessCategoryTopic(@PathVariable Long businessCategoryTopicId) {
        return topicService.deleteBusinessCategoryTopic(businessCategoryTopicId);
    }

    @ApiOperation(value = "修改题目及答案选项(总后台)", notes = "修改题目及答案选项(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "updateTopic", method = RequestMethod.POST)
    public ReturnVO updateTopic(@RequestBody Topic topic) {
        return topicService.saveTopic(topic);
    }

    @ApiOperation(value = "修改答案选项(总后台)", notes = "修改答案选项(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "updateTopicAnswer", method = RequestMethod.POST)
    public ReturnVO updateTopicAnswer(@RequestBody TopicAnswer topicAnswer) {
        return topicService.updateTopicAnswer(topicAnswer);
    }

    @ApiOperation(value = " 题库列表(总后台)", notes = " 题库列表(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "listTopic", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<Topic>>> listTopic(@RequestBody TopicDto topicDto) {
        return topicService.listTopic(topicDto);
    }

    @ApiOperation(value = "查询能力测评结果(总后台)", notes = "查询能力测评结果(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "selectBusinessCategoryEvaluationHistoryById/{businessCategoryEvaluationHistoryId}", method = RequestMethod.POST)
    public ReturnVO<BusinessCategoryEvaluationHistory> selectBusinessCategoryEvaluationHistoryById(@PathVariable Long businessCategoryEvaluationHistoryId) {
        return topicService.selectBusinessCategoryEvaluationHistoryById(businessCategoryEvaluationHistoryId);
    }

    @ApiOperation(value = "查询工厂体检/星级认证测评结果 0-工厂体检 1-星级认证(总后台)", notes = "查询工厂体检/星级认证测评结果 0-工厂体检 1-星级认证(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "selectBusinessCategoryRuleHistoryById/{businessCategoryRuleHistoryId}/{type}", method = RequestMethod.POST)
    public ReturnVO<BusinessCategoryRuleHistory> selectBusinessCategoryRuleHistoryById(@PathVariable Long businessCategoryRuleHistoryId, @PathVariable Integer type) {
        return topicService.selectBusinessCategoryRuleHistoryById(businessCategoryRuleHistoryId, type);
    }


    @ApiOperation(value = "修改测评建议(总后台)", notes = "修改测评建议(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "updateSuggest", method = RequestMethod.POST)
    public ReturnVO updateSuggest(@RequestBody UpdateSuggestDto updateSuggestDto) {
        return topicService.updateSuggest(updateSuggestDto);
    }

    @ApiOperation(value = "Excel根据题库类型导入题库(总后台)", notes = "Excel导入题库(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "importTopic/{topicCategoryId}", method = RequestMethod.POST)
    public ReturnVO importTopic(@RequestHeader String token, @PathVariable Long topicCategoryId, @RequestParam("file") MultipartFile file) {
        return topicService.importTopic(token, topicCategoryId, file);
    }

    @ApiOperation(value = "根据分类导出题库(总后台)", notes = "根据分类导出题库(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "exportTopic/{topicCategoryId}", method = RequestMethod.POST)
    public void exportTopic(HttpServletResponse response, @PathVariable Long topicCategoryId) {
        topicService.exportTopic(response, topicCategoryId);
    }
}
